package com.components.project.ui.fragment

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ToastUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.components.base.titlebar.TitleBar
import com.components.base.view.AutoMarqueeRecycleView
import com.components.base.view.CustomTextSwitcher
import com.components.base.view.MarqueeView
import com.components.project.MainActivity
import com.components.project.R
import com.components.project.ui.base.ProjectBaseFragment


class FunctionFragment : ProjectBaseFragment<MainActivity>() {

    private var titleBar: TitleBar? = null

    private var mData: MutableList<String> = mutableListOf()
    private var mData1: MutableList<String> = mutableListOf()
    private var mData2: MutableList<String> = mutableListOf()
    private var mData3: MutableList<String> = mutableListOf()
    private var mData4: MutableList<String> = mutableListOf()

    private var mListData: MutableList<MutableList<String>> = mutableListOf()

    private val recyclerMarqueeView: AutoMarqueeRecycleView by lazy { findViewById(R.id.recyclerMarqueeView) }

    override fun initData() {
        val horizontalTextSwitcher =
            findViewById<CustomTextSwitcher>(R.id.horizontalTextSwitcher)
        horizontalTextSwitcher.setInAnimation(android.R.anim.slide_in_left)
            .setOutAnimation(android.R.anim.slide_out_right)
            .bindData(mData)
            .setOnItemClickListener(object : CustomTextSwitcher.OnItemClickListener {
                override fun onItemClick(view: View, position: Int) {
                    ToastUtils.showShort(mData[position])
                }
            })
            .startSwitch(3000L)
        val verticalTextSwitcher = findViewById<CustomTextSwitcher>(R.id.verticalTextSwitcher)
        verticalTextSwitcher.setInAnimation(R.anim.window_down_up_in)
            .setOutAnimation(R.anim.window_down_up_out)
            .bindData(mData)
            .setOnItemClickListener(object : CustomTextSwitcher.OnItemClickListener {
                override fun onItemClick(view: View, position: Int) {
                    ToastUtils.showShort(mData[position])
                }
            })
            .startSwitch(3000L)
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_function
    }

    override fun initView() {
        titleBar = findViewById(R.id.titleBar)
        mData.add("习声回响② | 铸牢中华民族共同体意识 民族团结之花盛开在巴渝大地")
        mData.add("start解放军于近日在东南沿海等海空域组织演习.解放军于近日end")
        mData.add("北京市公布了生活垃圾分类治理三年行动计划。")
        mData.add("17日凌晨我国上空将出现一次月偏食。")
        mData.add("中国辛鑫夺得世锦赛公开水域游泳的金牌。")
        mData.add("一种是文字内容滚动，左右滚动很简单，设置好宽度，在onDraw中画出来就行了，这里介绍一下上下滚动的文本。")

        /*加载滚动TextView*/
        mData1.add("管控了个寂寞，花费好大的财力，人力，物力")
        mData1.add("迪迪哥肯定是共产党员,人作死就会死,放心那个机构已经立案调查了.")
        mData1.add("这个是不是阳性得监察机构说了算")
        mData2.add("不信谣，不传谣，半夜三根焊钢条")
        mData2.add("习声回响② | 铸牢中华民族共同体意识 民族团结之花盛开在巴渝大地")
        mData3.add("-----1-----")
        mData3.add("-----2-----")
        mData3.add("-----3-----")
        mData3.add("-----4-----")
        mData3.add("-----5-----")
        mData3.add("-----6-----")
        mData4.add("****强哥牛逼****")
        mData4.add("****强哥威武霸气****")
        mListData.add(0, mData)
        mListData.add(1, mData1)
        mListData.add(2, mData2)
        mListData.add(3, mData3)
        mListData.add(4, mData4)
        val marqueeViewAdapter = MarqueeViewAdapter(R.layout.item_marquee_view, mListData)
        recyclerMarqueeView.setRecordListSize(mListData.size)
        recyclerMarqueeView.layoutManager = LinearLayoutManager(activity)
        recyclerMarqueeView.adapter = marqueeViewAdapter
    }

    override fun onResume() {
        super.onResume()
        getStatusBarConfig()?.statusBarDarkFont(true)?.init()
    }

    inner class MarqueeViewAdapter(layoutResId: Int, data: MutableList<MutableList<String>>) :
        BaseQuickAdapter<MutableList<String>, BaseViewHolder>(
            layoutResId,
            data
        ) {

        override fun convert(holder: BaseViewHolder, item: MutableList<String>) {
            val tvMarqueeView = holder.getView<MarqueeView>(R.id.tvMarqueeView)
            tvMarqueeView.setTextRecordStateInterface {
                (this@MarqueeViewAdapter.recyclerView as AutoMarqueeRecycleView).flipStatus[holder.layoutPosition] = 1
                (this@MarqueeViewAdapter.recyclerView as AutoMarqueeRecycleView).doAllFlip()
            }
            tvMarqueeView.setContent(item as ArrayList<String>)
            tvMarqueeView.setItemClick { position -> ToastUtils.showShort(item[position]) }
        }

    }

}